package edu.wfu.preparedDishes.commodity.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import edu.wfu.preparedDishes.common.utils.PageUtils;
import edu.wfu.preparedDishes.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import edu.wfu.preparedDishes.commodity.entity.ClassificationEntity;
import edu.wfu.preparedDishes.commodity.service.ClassificationService;




/**
 * 商品分类表;
 *
 * @author ljh
 * @email hero_miracle@gmail.com
 * @date 2023-11-27 17:17:46
 */
@RestController
@RequestMapping("commodity/classification")
public class ClassificationController {
    @Autowired
    private ClassificationService classificationService;


    @RequestMapping("/listByMerchantId")
    public R list(@RequestParam(name = "merchantId", defaultValue = "1001") String merchantId){
        List<ClassificationEntity> classificationEntities = classificationService.queryByMerchantId(merchantId);
        return R.ok().put("page", classificationEntities);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = classificationService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{classifyId}")
    public R info(@PathVariable("classifyId") String classifyId){
		ClassificationEntity classification = classificationService.getById(classifyId);

        return R.ok().put("classification", classification);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ClassificationEntity classification){
		classificationService.save(classification);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ClassificationEntity classification){
		classificationService.updateById(classification);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] classifyIds){
		classificationService.removeByIds(Arrays.asList(classifyIds));

        return R.ok();
    }

}
